﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

using BusinessLogic.BusinessRules;
using BusinessLogic.ClassFactory;
using DataAccess;
using Model;
using EncryptUtily;
using ValidateCommon;

namespace RichECMS.IWebServices
{
    /// <summary>
    /// LoginWebSite 的摘要说明
    /// 用户C/S图片上传工具登陆验证
    /// 张仪
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class LoginWebSite : System.Web.Services.WebService
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strUserName"></param>
        /// <param name="strPsw"></param>
        /// <returns>0:成功；1没有此用户；2:用户名错误，请重新填写！；3:密码错误，请重新填写！</returns>
        [WebMethod]
        public string CsLoginValidate(string strUserName,string strPsw)
        {
            string strReturn = "0";
            try
            {
                using (DBManager _DBManager = new DBManager())
                {
                    strUserName = EncryptUtily.EncryptUtily.LoginDecrypt(UTF8code.DeRepleaseDES(strUserName));
                    strPsw = EncryptUtily.EncryptUtily.LoginDecrypt(UTF8code.DeRepleaseDES(strPsw));
                    UserManageInfoFactory objFactory = new UserManageInfoFactory(_DBManager);
                    string strWhere = "chvLoginName =?";
                    UserManageInfo objUserManageInfo = objFactory.CreatorByParm(strWhere, strUserName);
                    if (objUserManageInfo == null)
                    {
                        strReturn = "1";
                    }
                    if (objUserManageInfo.DataItem.chvLoginName.Trim() != strUserName)
                    {
                        strReturn = "2";
                    }
                    string strDBPsw = EncryptUtily.EncryptUtily.LoginDecrypt(objUserManageInfo.DataItem.chvLoginPsw);
                    if (strPsw != strDBPsw)
                    {
                        strReturn = "3";
                    }
                    objFactory.Dispose();
                }
            }
            catch (Exception ex)
            {
                strReturn = "10000";
            }
           
            return strReturn;

        }
    }
}
